package com.blog.file.controller;

import com.blog.Config;
import com.tcj.blog.dto.JsonResult;
import com.tcj.blog.dto.ResponseCode;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.UUID;

/**
 * 2 * @Author: Tcj
 * 3 * @Date: 2021/1/15 16:29
 * 4
 */
@RestController
@CrossOrigin
@Component
@Api(tags = "文件上传接口")
public  class  Upload{
    @PostMapping("/uploadfile")
    @ResponseBody
    public JsonResult upload(@RequestParam("file") MultipartFile file,@RequestParam("id") String id) throws IOException {
        String fileName = "userTemp"+id +".jpg";
        file.transferTo(new File( Config.updatePath+ fileName));
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(fileName);
        jsonResult.setStatus(ResponseCode.OK);
        return jsonResult;
    }
}
